﻿using Share;
using System.Collections.Generic;
using UnityEngine;
public class ActionNodeBase : MonoBehaviour
{
    static int VERSION = 1;
    #region 编辑器数据
    public int GID;
    public Rect m_rectPos = new Rect(500, 100, 300, 300); // 编辑器里显示的位置
    public bool m_bMin = false;
    public int m_nVersion = 0;
    public string GetNodeName()
    {
        return m_strDesc;
    }
    public Rect WindowRect
    {
        get { return m_rectPos; }
        set { m_rectPos = value; }
    }
    #endregion
    public string m_strDesc;
    public SmartParam m_spDelayTime = new SmartParam(0);
    public int m_gid;                  // 这个节点的索引id
    public int m_IndexID = -1;         // 索引

    public virtual bool OnCombin()
    {
        //try
        //{
        //    DoInitSmartParam(null);
        //}
        //catch(Exception e)
        //{
        //    LogMgr.Instance.LogError("Profabs name = {0} ", gameObject.name );
        //}
        return false;
    }
    public void Start()
    {

    }
    public virtual int GetVersion()
    {
        return -1;
    }
    public bool Combin()
    {
        //if (m_nVersion < GetVersion() )
        {
            if (OnCombin() == false)
                return false;
            m_nVersion = GetVersion();
            return true;
        }
        //return false;
    }

    public virtual void DoInitSmartParam(Dictionary<string, string> dic)
    {
        m_spDelayTime.DoInit(dic);
    }
    public System.Type getFieldType(string fieldName)
    {
        return GetType().GetField(fieldName).FieldType;
    }
    public object getFieldValue(string fieldName)
    {
        if (GetType().GetField(fieldName) == null)
        {
            XKLog.LogError("没有{0}名字的变量，编辑器检查逻辑!", fieldName);
            return null;
        }
        return this.GetType().GetField(fieldName).GetValue(this);
    }
    public void setFieldValue(string fieldName, object val)
    {
        var Ts = this.GetType();
        Ts.GetField(fieldName).SetValue(this, val);
    }
    public virtual void NodeCopy(ActionNodeBase node)
    {

    }
    public virtual void DoDataCheck()
    {
    }

    public void DoDraw()
    {
        WindowRect = GUI.Window(GID, WindowRect, DoFreshNode, "Show");// GetNodeName());
    }

    public virtual void DoFreshNode(int id)
    {
    }
}
